fix(spv): compute required proof headers from actual header difficulties#4038
Closed
lionakhnazarov wants to merge 92 commits into
Closed
fix(spv): compute required proof headers from actual header difficulties#4038lionakhnazarov wants to merge 92 commits into
lionakhnazarov wants to merge 92 commits into
Conversation
- Introduced Testnet4 configuration in with a new Electrum server URL. - Updated to include Testnet4 for Bitcoin networks. - Added Testnet4 constant in for better network identification. - Adjusted test cases in for improved readability. - Updated Hardhat configuration files to streamline deployment processes and handle potential errors during verification.
…ort.json file - Removed a defunct Thesis Electrum URL from the expected peers in . - Deleted the file as it is no longer needed, streamlining the project structure.
…ackage.json and yarn.lock for ECDSA and random-beacon
…abi version in ECDSA and random-beacon
…g in deployment scripts
… script for improved environment isolation
…fig file and enhancing environment handling
…ardhat-verify after Hardhat 3 upgrade, clarifying API compatibility
…ent for mainnet compatibility
… replace deprecated IP address
…n test networks to improve reliability
…ailable data for various networks
…ervers and adding error handling for integration tests
…to skip outdated public endpoints
…tOwner function with governance checks and error handling
… addresses, transaction hashes, and gas usage metrics
withdrawRewards resolves the beneficiary via _currentAuthorizationSource(). Replace stale NOT MIGRATED / TokenStaking-only commentary with accurate routing, delegated-setup divergence, TIP-092/100 reward halt context, and future reactivation semantics. Made-with: Cursor
…s and update Hardhat configuration for plugin compatibility
…resses, transaction hashes, and gas metrics for multiple contracts
…specific group parameters for improved deployment on testnets
…for enhanced group parameter configuration
…ain for reliable retargeting
…aintainer for handling preflight errors gracefully
…improved transaction confirmation reliability
…ficulty maintainer's pre-retarget validation for better handling of minimum-difficulty blocks
…resses, transaction hashes, and gas metrics for multiple contracts
…ialization for improved readability
…ic block sequence and simplifying timeout handling for better reliability
…n to ensure proper behavior when multiple members submit claims
…g in DKG execution
The rebase used -X theirs to resolve conflicts, which silently dropped two items that existed in both main and the pre-rebase branch: - .github/workflows/contracts-ecdsa.yml: --compile-force-framework hardhat flag for slither - solidity/ecdsa/package.json: get-func-name ^2.0.2 resolution
Mirrors recent dependabot bumps on main: - handlebars 4.7.7 -> 4.7.9 (random-beacon threshold-network#3916, prototype pollution fix) - immutable 4.0.0-rc.15 -> 4.3.8 (random-beacon threshold-network#3879) Added as Yarn 4 resolutions in both random-beacon and ecdsa to keep parity across solidity workspaces and avoid post-merge dependabot churn.
Duplicate Allowlist identifier in test imports broke both lint (no-redeclare) and tsc (TS2300) builds on CI.
getProofInfo assumed every proof header carries the relay epoch difficulty, so with txProofDifficultyFactor=1 it assembled single-header proofs. On testnet4 (BIP94), sweeps mined in minimum-difficulty blocks produced proofs containing only a DIFF1 header, which the Bridge rejects with "Not at current or previous difficulty". Mirror the Bridge's BitcoinTx logic instead: skip leading DIFF1 headers when both relay epochs are above minimum, bind the requested difficulty to the first decisive header matching the relay's current or previous epoch difficulty, and accumulate headers until their total observed difficulty covers requestedDifficulty * txProofDifficultyFactor.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR updates Git/Yarn setup for CI, changes Bitcoin/Ethereum and maintainer proof handling, and reworks Solidity ECDSA and Random Beacon deployment, fixture, and test flows for Sepolia, allowlist defaults, and legacy TokenStaking compatibility. ChangesCI and Yarn setup
Bitcoin, Ethereum, and maintainer logic
Solidity ECDSA and Random Beacon
Sequence Diagram(s)sequenceDiagram
participant Workflow as GitHub Actions workflow
participant Git as setup-git-for-yarn
participant Yarn as Corepack/Yarn 4.8.1
participant Docs as reusable-solidity-docs
Workflow->>Git: prepare safe git wrapper
Workflow->>Yarn: enable and install dependencies
Workflow->>Docs: call reusable docs workflow
Docs->>Yarn: run hardhat docgen
sequenceDiagram
participant Maintainer as SPV/Btcdiff maintainer
participant Chain as Bitcoin chain
participant Relay as LightRelay
participant Config as IdleOnPreflightFailure
Maintainer->>Chain: load headers and difficulty targets
Chain->>Relay: validate pre-retarget difficulty
Relay-->>Maintainer: ErrUniformPreRetargetDifficulty or proof data
Maintainer->>Config: decide idle vs fail
Changes
Suggested reviewers
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(spv): compute required proof headers from actual header difficulties
Problem
The SPV maintainer computed the number of block headers for a proof assuming every header carries the relay epoch difficulty: with
txProofDifficultyFactor = 1it always assembled a single-header proof. On testnet4 (BIP94), sweep transactions are regularly mined in minimum-difficulty (DIFF1) blocks, so the proof contained only a DIFF1 header. The Bridge skips DIFF1 headers when binding to the relay difficulty, finds no decisive header, and reverts with:Because the error is deterministic, the maintainer crash-looped on the same transaction every cycle (
error while maintaining SPV: ... restarting maintainer), and the affected wallet's main UTXO could never be registered on the host chain — blocking all subsequent sweeps for that wallet.Fix
getProofInfonow mirrors the Bridge'sBitcoinTx.determineRequestedDifficulty/evaluateProofDifficultylogic instead of assuming a fixed per-header difficulty:requestedDifficulty × txProofDifficultyFactor,maxProofHeaders = 144and report "wait for more confirmations" when the chain tip is reached first.The old epoch-boundary block-count arithmetic is removed; epoch spans are handled implicitly by summing actual header difficulties.
Testing
TestGetProofInforewritten for the new semantics: current/previous-epoch proofs, epoch-spanning proofs with difficulty drop/raise, leading DIFF1 headers, relay at minimum difficulty, decisive-header mismatch, DIFF1 run exceeding the header bound, and chain tip reached early. Headers are generated with real compact-bits encoding (blockHeaderWithDifficulty).go test ./pkg/maintainer/spvpasses.876510fd...62c8, mined in a DIFF1 block at height 137542) was proven on the first cycle after deploying this fix —submitDepositSweepProoftx0xfeeefad32c7116727949483edfb1e38f8117d923521fd3467886a05226b82577, status 1 — and the maintainer completed its round cleanly.Notes
determineRequestedDifficulty(deployed via the DIFF1 library upgrade); against an older Bridge the maintainer now skips such transactions instead of crash-looping.Summary by CodeRabbit
Release Notes
New Features
Improvements
Configuration
IdleOnPreflightFailureoption for Bitcoin difficulty maintainer.